﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using RoomSvc.Data;
using RoomService.Service;

namespace RoomService.Account
{
    public partial class SignIn : System.Web.UI.Page
    {
        protected void Page_Init(Object sender, EventArgs e)
        {
            btnTest.Click += new EventHandler(this.btnTest_Click);
        }

        protected void Page_Load(Object sender, EventArgs e)
        {
        }

        protected void btnTest_Click(Object sender, EventArgs e)
        {
            string user = username.Value;
            string pass = password.Value;
            int userid = -1;
            RoomSvc.Data.Person[] persons = RoomService.Service.ServiceClient.GetPersons();
            RoomSvc.Data.Person pUser = null;
            foreach (RoomSvc.Data.Person p in persons)
            {
                if (p.username == user && p.password == pass)
                {
                    userid = p.Pers_id;
                    pUser = RoomService.Service.ServiceClient.GetPerson(userid.ToString());
                    break;
                }
                else
                {
                    continue;
                }
            }
            RoomService.Global.currentUser = pUser;
            Response.Redirect("../Default.aspx");
        }
    }
}